from selenium import webdriver
from time import sleep
from random import randint

driver =webdriver.Chrome()
# url='https://www.huya.com/g/2793'
# url='https://www.huya.com/g/cf#tag122'
url='https://www.huya.com/g/3203'
driver.get(url)
num=1
while True:
    print("---------------"+"第"+str(num)+"页"+"----------------")
    num=num+1
    sleep(5)
    html=driver.page_source
    # names=driver.find_element_by_xpath('//i[@class="nick"]')
    #加s表示找多个，不加s只找一个
    names=driver.find_elements_by_xpath('//span[@class="txt"]/span[@class="avatar fl"]/i[@class="nick"]')
    # counts=driver.find_element_by_xpath('//i[@class="js-num"]')
    counts=driver.find_elements_by_xpath('//span[@class="txt"]/span[@class="num"]/i[@class="js-num"]')
    for name,count in zip(names,counts):
        print(name.text+":"+count.text)
    # sleep(randint(3,5))
    if driver.page_source.find('laypage_next')!=-1:
        driver.find_element_by_xpath('//a[@class="laypage_next"]').click()
    else:
        break


# print(html)





